package vn.mahjonggame.game.request;

import java.util.List;

import vn.mahjonggame.game.Mahjong;
import vn.mahjonggame.game.MahjongExtension;
import vn.mahjonggame.metadata.GameActionType;
import vn.mahjonggame.metadata.ResponseCode;
import vn.mahjonggame.metadata.MObject;
import vn.mahjonggame.util.Common;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class ReadyHandler extends BaseClientRequestHandler {
		
	@Override
	public void handleClientRequest(User user, ISFSObject params) {
		// TODO Auto-generated method stub
		MahjongExtension ext = (MahjongExtension) getParentExtension();
		Mahjong mahjong = ext.getMahjong();
		
		List<User> users = user.getLastJoinedRoom().getUserList();
				
		ext.setPlayerReady(user);		
		
		SFSObject data = new SFSObject();
		
		data.putInt(MObject.smartfox_user_id.toString(), user.getId());
		
		SFSObject response = mahjong.makeResponse(ResponseCode.SUCCESS, data);
		
		send(GameActionType.ready.toString(), response, users);
		
		ext.addAction(user, GameActionType.ready.toString());
	}
}
